<template>
    <div class="app-container">
        <div class="warp_padding">  
            <div class="head-container">
                <!-- 搜索 -->
                <label id="labelQuery" class="labelQuery">学校名称: </label>
                <el-input v-model="formDate.schName" clearable placeholder="学校名称搜索" style="width: 150px;" class="filter-item" @keyup.enter.native="toQuery" @change="toQuery()"/>
                
                <span v-if="device!=='mobile'">
                    <label class="labelQuery">主讲教室名称: </label>
                    <el-input v-model="formDate.crName" clearable placeholder="主讲教室名称" style="width: 150px;" class="filter-item" @keyup.enter.native="toQuery" @change="toQuery()"/>

                    <label class="labelQuery">教室类型: </label>
                    <el-select v-model="formDate.roomType" clearable placeholder="教室类型搜索" @change="toQuery()" style="width: 130px;">
                        <el-option
                              v-for="item in roomTypes"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id" >
                        </el-option>
                    </el-select>

                    <label class="labelQuery">科目: </label>
                    <el-select v-model="formDate.subjectId" clearable placeholder="科目搜索" @change="toQuery()" style="width: 130px;">
                        <el-option
                              v-for="item in subjectNames"
                              :key="item.id"
                              :label="item.couName"
                              :value="item.id" >
                        </el-option>
                    </el-select>

                    <!-- <label class="labelQuery">县/区: </label>
                    <area-item @getMessage="showMsg" /> -->
                </span>
     

                <el-button class="filter-item" size="mini" type="primary" icon="el-icon-search" @click="toQuery">搜索</el-button>
                
            </div>


            <!--列表-->
            <el-table :data="lists" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;" max-height="650">
                <!-- <el-table-column type="selection" width="30"></el-table-column> -->
                
                <el-table-column type="index" width="45"></el-table-column>
                
                <!-- <el-table-column prop="areaName" label="县/区"  sortable :show-overflow-tooltip="true"></el-table-column>           
                <el-table-column prop="schName"  :show-overflow-tooltip="true" label="所属校群" ></el-table-column> -->

                <el-table-column prop="schName"  min-width="130" :show-overflow-tooltip="true" label="所属学校" ></el-table-column>

                <el-table-column prop="roomType" label="教室类型" :formatter="roomType"></el-table-column>

                <el-table-column prop="subjectName" label="科目"></el-table-column>

                <el-table-column prop="weekName" label="星期几"></el-table-column>
                <el-table-column prop="lessonName" label="第几节"></el-table-column>

                <!-- <el-table-column prop="startTimeString" label="上课时间"></el-table-column> -->

                <el-table-column prop="createtime" label="上课时间"  min-width="120" sortable>
                    <template slot-scope="scope">
                      <span>{{ scope.row.startTimeString}} 至 {{scope.row.endTimeString}}</span>
                    </template>
                </el-table-column>

                <el-table-column prop="lectureTeaId" label="主讲老师"></el-table-column>
                <el-table-column prop="crName" label="主讲教室名称" min-width="130" :show-overflow-tooltip="true"></el-table-column>

                <!-- <el-table-column label="操作" width="150">
                    <template slot-scope="scope">
                        <el-button size="mini" type="success" v-if="checkPermission(['sch_all','sch_edit'])" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                        <el-button type="danger" size="mini" v-if="checkPermission(['sch_all','sch_del'])" @click="handleDel(scope.$index, scope.row.id)">删除</el-button>
                    </template>
                </el-table-column> -->

                <!-- <el-table-column prop="status" label="状态"  class="staus">
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.status | statusFilter">{{scope.row.status | formatStata}}</el-tag>
                    </template>
                </el-table-column> -->
            </el-table>
        </div>

        <!--工具条-->
        <el-col :span="24" class="toolbar">
            <el-button type="danger" size="mini" @click="batchRemove" :disabled="this.sels.length===0" v-if="checkPermission(['sch_all','sch_del'])" class="remove">批量删除</el-button>

            <el-pagination background  @size-change="handleSizeChange"  @current-change="handleCurrentChange"  :current-page.sync="formDate.pageNo" :page-count="pageCount" :page-sizes="[10, 20, 30, 50,100]"  layout="total, sizes,prev, pager, next, jumper" :pager-count="pagerCount" :total="total" class="pagination"></el-pagination>
        </el-col>

    </div>
</template>

<script>

import areaItem from '@/components/area/areaitem'
import checkPermission from '@/utils/permission' 
import { parseTime } from '@/utils/index'
import {  couName, classdetailList, schoolDel  } from '@/api/request'
import { mapGetters } from 'vuex'
export default {
    components: {  areaItem},
    computed: {
        ...mapGetters([
          'device'
        ])
    },
    filters: {
       // el-tag类型转换
        statusFilter(status) {
            const statusMap = {
                0: 'success',
                1: 'warning',
                2: 'info',
                4: 'danger',
                5: 'success'
            }
            return statusMap[status]
        },
       // 状态显示转换
        formatStata(status) {
            const statusMap = {
                0: '启用',
                1: '未发布',
                2: '待审核',
                3: '审核通过',
                4: '审核失败',
                5: '发布成功',
                6: '发布失败'
            }
            return statusMap[status]
        }
    },
    data() {
        return {
            subjectNames:[],
            pageCount: 0,
            total:0,  
            listLoading: false,
            lists: [],
            sels: [],//列表选中列
            pagerCount:11,   
            formDate:{
                pageNo: 1,  
                pageSize:10,
                schId:'',
                schName:'',
                roomType:'',
                crName:'',
                subjectId:''
            },
            isAdd:true,
            roomTypes: [
                {
                    id: '0',
                    name: '精品教室'
                },
                {
                    id: '1',
                    name: '主讲教室'
                },
                {
                    id: '2',
                    name: '专业互动教室'
                },
                {
                    id: '3',
                    name: '直播互动教室'
                },
                {
                    id: '4',
                    name: '直播教室'
                },
            ],
         }
    },
    methods: {
        parseTime,
        checkPermission,
        showMsg(tir){
            this.formDate.areaCode = tir;
            this.init()
        },
        roomType(row, column) {
            return row.roomType == 0 ? '精品教室' : row.roomType == 1 ? '主讲教室' : row.roomType == 2 ? '专业互动教室' : row.roomType == 3 ? '直播互动教室' : row.roomType == 4 ? '直播教室': '未知';
        },
        selsChange: function (sels) {
                this.sels = sels;
        },
        handleCurrentChange(val) {
            this.formDate.pageNo = val;
            this.init()
        },
        handleSizeChange(val) {
            this.formDate.pageSize = val
            this.init()
            // console.log(`page ${val}`);
        },
        toQuery(){
            this.init()
        },
        
        init(){
            this.listLoading = true
            let params = {...this.formDate}
            classdetailList(params).then(res => { 
                let { list, total } = res
                this.lists = list
                this.total = total
                this.listLoading = false 
            })
        },
        ready(){
            couName().then(res =>{
                this.subjectNames = res.data
            })
        },        
        handleEdit(index, row) {
            this.isAdd = false
            this.$refs.form.dialog = true
            let Resuts = Object.assign({}, row) 
            let isCock = Resuts.isCock.toString()
            let schLevel  = Resuts.schLevel.toString()
            Resuts.isCock = isCock
            Resuts.schLevel = schLevel
            this.$refs.form.form = Resuts
        },
        batchRemove(){
            let ids = this.sels.map(item => item.id);
            this.$confirm('确认删除选中的记录吗?', '提示', {
                        type: 'warning'
                    }).then(() => {
                        this.listLoading = true;
                        schoolDel(ids).then(res => {
                            this.listLoading = false;
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            this.init();
                        })

                    }).catch(() => {
            });
        },
        handleDel(index,ID){
            let ids = [];
            ids.unshift(ID)
            this.$confirm('确认删除该记录吗?', '提示', {
                        type: 'warning'
                    }).then(() => {
                        // console.log(ids)
                        this.listLoading = true;
                        schoolDel(ids).then(res => {
                            this.listLoading = false;
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            this.init();
                        })

                    }).catch(() => {
            });
        },
    },
    mounted:function(){
        this.init()
        this.ready()
    },
}

</script>


<style scoped lang="scss">
.remove{
    display: none
}
</style>
